package io.mft.runtime.config;

import java.util.List;

import io.mft.commons.config.datasource.DSConfig;
import io.mft.commons.config.mq.MqConfig;
import io.mft.dev.base.ApiThreadExecutorConfig;
import io.mft.dev.base.MFTRuntimeConfig;
import io.mft.dev.base.cache.RegionConfig;
import io.mft.flow.core.FlowExecutor;
import io.mft.runtime.cache.ApiCache;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class RuntimeResource {
	private final ApiCache apiCache;
	private final FlowExecutor flowExecutor;
	private DSConfig dsConfig;
	private List<MqConfig> mqConfigs;
	private List<RegionConfig<?>> regionConfigs;
	private List<ApiThreadExecutorConfig> apiThreadExecutorConfigs;
	private boolean inited;
	
	public RuntimeResource(ApiCache apiCache,FlowExecutor flowExecutor) {
		this.apiCache=apiCache;
		this.flowExecutor=flowExecutor;
	}
	
	public MFTRuntimeConfig runtimeConfig() {
		MFTRuntimeConfig runtimeConfig=new MFTRuntimeConfig();
		apiCache.getApis().forEach(api->{
			runtimeConfig.getApiMap().put(api.getKey(), api);
		});
		runtimeConfig.getApis().addAll(apiCache.getApis());
		runtimeConfig.getApiThreadExecutorConfigs().addAll(apiThreadExecutorConfigs);
		runtimeConfig.getDsConfig().putAll(dsConfig);
		runtimeConfig.getMqConfigs().addAll(mqConfigs);
		runtimeConfig.getRegionConfigs().addAll(regionConfigs);
		return runtimeConfig;
	}
}
